package com.itbaima.service.impl;

import com.itbaima.aop.InvokeLog;
import com.itbaima.entity.User;
import com.itbaima.mapper.UserMapper;
import com.itbaima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    @InvokeLog // 在需要被增强的方法上加上自定义注解以实现增强
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    @Transactional // 声明式事务
    public void insertUser() {
        User user = new User(null, "sg666", 15, "上海");
        User user2 = new User(null, "sg777", 16, "北京");
        userMapper.insertUser(user);
        System.out.println(1/0); // 模仿抛出异常
        userMapper.insertUser(user2);
    }
}
